<template>
    <div class='orderSetting'>
        <div class="container">
            <el-header>本地生活公共参数配置</el-header>
            <el-main>
                <el-form ref="form" :model="form" :rules="rules" label-width="200px" v-loading="formLoading" size="medium" style="margin-top:30px; margin-left:60px;">
                    <el-form-item label="是否可购买电影票：" prop="life_movie_is_pay">
                        <el-col style="text-align: left;">
                            <el-radio-group v-model="form.life_movie_is_pay" >
                                    <el-radio v-for="dict in yesNo" :key="dict.dictValue" :label="Number(dict.dictValue)">{{ dict.dictLabel }}
                                    </el-radio>
                                </el-radio-group>
                        </el-col>
                        <!-- <span style="position: absolute; left:56%; font-size: 14px; color:#8492a6;">未付款，订单自动关闭</span> -->
                    </el-form-item>
                    <el-form-item label="电影票打折比例：" prop="life_movie_ratio">
                        <el-col :span="10">
                            <el-input v-model="form.life_movie_ratio" @keyup.native="form.life_movie_ratio=onInput(form.life_movie_ratio)" placeholder="请输入">
                                <!-- <template slot="append">天</template> -->
                            </el-input>
                        </el-col>
                        <span style="position: absolute;left:50%; font-size: 14px; color:#8492a6;">单位: %, (填100, 表示不打折)</span>
                    </el-form-item>
                    <el-form-item label="电影票一级大团长抽成比例：" prop="life_movie_one_tc_take_rata">
                        <el-col :span="10">
                            <el-input v-model="form.life_movie_one_tc_take_rata" @keyup.native="life_movie_one_tc_take_rata=onInput1(form.life_movie_one_tc_take_rata)" placeholder="请输入">
                                <!-- <template slot="append">天</template> -->
                            </el-input>
                        </el-col>
                        <span style="position: absolute;left:50%; font-size: 14px; color:#8492a6;">单位: %, (小于零使用总后台设置的默认比例)</span>
                    </el-form-item>
                    <el-form-item label="电影票二级大团长抽成比例：" prop="life_movie_two_tc_take_rata">
                        <el-col :span="10">
                            <el-input v-model="form.life_movie_two_tc_take_rata" @keyup.native="form.life_movie_two_tc_take_rata=onInput1(form.life_movie_two_tc_take_rata)" placeholder="请输入">
                                <!-- <template slot="append">天</template> -->
                            </el-input>
                        </el-col>
                        <span style="position: absolute;left:50%; font-size: 14px; color:#8492a6;">单位: %, (小于零使用总后台设置的默认比例)</span>
                    </el-form-item>
                    <el-form-item label="电影票一级团长抽成比例：" prop="life_movie_one_gl_take_rata">
                        <el-col :span="10">
                            <el-input v-model="form.life_movie_one_gl_take_rata" @keyup.native="form.life_movie_one_gl_take_rata=onInput1(form.life_movie_one_gl_take_rata)" placeholder="请输入">
                                <!-- <template slot="append">天</template> -->
                            </el-input>
                        </el-col>
                        <span style="position: absolute;left:50%; font-size: 14px; color:#8492a6;">单位: %, (小于零使用总后台设置的默认比例)</span>
                    </el-form-item>
                    <el-form-item label="电影票二级团长抽成比例：" prop="life_movie_two_gl_take_rata">
                        <el-col :span="10">
                            <el-input v-model="form.life_movie_two_gl_take_rata" @keyup.native="form.life_movie_two_gl_take_rata=onInput1(form.life_movie_two_gl_take_rata)" placeholder="请输入">
                                <!-- <template slot="append">天</template> -->
                            </el-input>
                        </el-col>
                        <span style="position: absolute;left:50%; font-size: 14px; color:#8492a6;">单位: %, (小于零使用总后台设置的默认比例)</span>
                    </el-form-item>
                    <el-form-item label="团长升大团长总消费额：" prop="dist_promote_turnover">
                        <el-col :span="10">
                            <el-input v-model="form.dist_promote_turnover" @keyup.native="form.dist_promote_turnover=onInput(form.dist_promote_turnover)" placeholder="请输入">
                                <!-- <template slot="append">天</template> -->
                            </el-input>
                        </el-col>
                        <span style="position: absolute;left:50%; font-size: 14px; color:#8492a6;">单位: 元</span>
                    </el-form-item>
                    <el-form-item label="团长升大团长拉新人数：" prop="dist_promote_recruits">
                        <el-col :span="10">
                            <el-input v-model="form.dist_promote_recruits" @keyup.native="form.dist_promote_recruits=handleNum(form.dist_promote_recruits)" placeholder="请输入">
                                <!-- <template slot="append">天</template> -->
                            </el-input>
                        </el-col>
                        <!-- <span style="position: absolute;left:50%; font-size: 14px; color:#8492a6;">单位: %, (填100, 表示不打折)</span> -->
                    </el-form-item>
                </el-form>

                <el-row>
                    <el-col :span="20">
                        <el-button type="primary" @click="submit" :disabled="formLoading">提交</el-button>
                    </el-col>
                </el-row>
            </el-main>
            <!-- <el-footer>
                <el-button type="primary" @click="submit" :disabled="formLoading">确 定</el-button>
            </el-footer> -->
            <!-- <span slot="footer" class="dialog-footer">
                <el-button @click="close()">取 消</el-button>
                <el-button type="primary" @click="submit" :disabled="formLoading">确 定</el-button>
            </span> -->
        </div>
    </div>
</template>
<script>
import { setConfigsInfo, getConfigsInfo } from "@/api/basic/params.js"
import { yesNo } from "@/api/dictionary"
import throttle from 'lodash.throttle'
export default {
    name: 'medicalHistoty',
    props: {

    },
    data() {
        const isRange = (rule,value,callback) =>{
            if(value < 0 || value > 100){
                return callback(new Error('输入数字需要在0~100之间'))
            } else {
        callback()
      }
        }
        const isRange0 = (rule,value,callback) =>{
            if(value > 100){
                return callback(new Error('输入数字需要小于100'))
            } else {
        callback()
      }
        }
        return {
            loading: false,
            yesNo: yesNo,
            handleShow: "",
            formLoading: false,
            form: {
                life_movie_is_pay:'',
            },
            rules: {
                life_movie_ratio:[{ required: false, message: "请输入提现金额", trigger: "blur" }, {validator: isRange, trigger: 'blur'}],
                life_movie_one_tc_take_rata:[{ required: false, message: "请输入提现金额", trigger: "blur" }, {validator: isRange0, trigger: 'blur'}],
                life_movie_two_tc_take_rata:[{ required: false, message: "请输入提现金额", trigger: "blur" }, {validator: isRange0, trigger: 'blur'}],
                life_movie_one_gl_take_rata:[{ required: false, message: "请输入提现金额", trigger: "blur" }, {validator: isRange0, trigger: 'blur'}],
                life_movie_two_gl_take_rata:[{ required: false, message: "请输入提现金额", trigger: "blur" }, {validator: isRange0, trigger: 'blur'}],
                
            },
        }
    },
    created() {
        this.getConfigsInfo()  
    },
    methods: {
        getConfigsInfo(){
            getConfigsInfo().then(res => {
                console.log(res,'000')
                this.form = res.data
            })
        }, 
        submit: throttle(function () {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    this.formLoading = true;
                    setConfigsInfo(this.form).then(res => {
                        this.msgSuccess("操作成功！");
                        // this.close()
                        this.formLoading = false;
                    }).catch(() => {
                        this.formLoading = false;
                    })
                }
            })
        }, 1000, { trailing: false }),
    }
}
</script>

<style lang='scss' scoped>
.el-header {
    width: 85%;
    background-color: #F3F3F3;
    // color: #333;
    text-align: center;
    line-height: 60px;
}

.el-main {
    width: 85%;
    border: 1px solid #E4E4E4;
    text-align: center;
    line-height: 160px;
}
</style>
